package com.guigu.gcservice.controller;


import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.guigu.commonutils.R;
import com.guigu.gcservice.entity.Say;
import com.guigu.gcservice.entity.User;
import com.guigu.gcservice.service.SayService;
import com.guigu.gcservice.service.UserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.sql.Wrapper;

/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author testjava
 * @since 2021-05-31
 */
@RestController
@RequestMapping("/gcservice/user")
@CrossOrigin
public class UserController {

    @Autowired
    private UserService userService;

    //登录
    @PostMapping("login")
    public R login(  String username,
                     String password) {
        QueryWrapper<User> wrapper = new QueryWrapper<>();
        wrapper.eq("username", username);
        User one = userService.getOne(wrapper);
        if (null != username && null != password) {
            if (one.getUsername().equalsIgnoreCase(username)) {
                if (one.getPassword().equalsIgnoreCase(password)) {
                    return R.ok();
                } else {
                    return R.error().data("message","密码错误");
                }
            }else {
                return R.error().data("message","账号或密码错误");
            }
        }else{
            return R.error().data("message","没有此账号");
        }
        //return null;
    }

}




